<?php
	chdir(dirname(__FILE__));
	// error_reporting(E_ERROR);
	set_time_limit(0); // 脚本将永久运行
	require_once ("../../config.php");//引入配置
	require_once ("../../log.php");
	require_once ("../api_tool.php");
	require_once ("core.php");
	require_once ("../api_wxsend_cat.php");

	// define("API_URL","http://127.0.0.1:8073/send");
	// define("API_URL","http://127.0.0.1:8073/send");
	// define("LOGIN_URL","http://127.0.0.1:1688/");
	// define("KEY","DB50FF2D30C14b68AB315D127BFDE9CF");

	// LOGINFO($_GET, "=== _GET");
	/**
	 **	淘宝接口
	 ** 发送一个商品信息到达微信群(此格式为固定格式)
	 **
	 **/ 
	
	$emoji_array = array (
		"[Commando]", "[Determined]", "[Clap]", "[Watermelon]", 	// 闲 努力 鼓掌 水果
		"[Beer]", "[Basketball]", "[PingPong]", "[Coffee]", 		// 酒 篮球 乒乓 咖啡
		"[Rice]", "[Rose]", "[Lips]", "[Heart]", "[Cake]",   		// 美食 鲜花 唇 爱心 生日
		"[强]","[玫瑰]","[太阳]","[耶]","[拳头]","[蛋糕]",
		"[嘴唇]","[爱心]","[跳跳]","[转圈]","[福]","[红包]",
	);


	$_wx = array();
	$_wx['bot_wxid'] = $_GET['robot_wxid'];
	$_wx['from_wxid'] = $_GET['wechat_room_id'];

	// 发单开头标语
	$_item = array();
	$_item['msg'] = BASE_PATH."boximg/{$_GET['good_img']}";
	$_item['msg_type'] = 47;
	cat_send_msg($_wx, $_item);
	sleep(2);

	// 随机一个表情
	$rand_emoji = $emoji_array[array_rand($emoji_array)];

	// 组建标题文字说明
	$text = "{$rand_emoji}{$_GET['cat_leaf_name']}";
	$_item = array();
	$_item['msg'] = $text;
	$_item['msg_type'] = 1;
	cat_send_msg($_wx, $_item);
	sleep(2);

	// 发送图片
	$i = 1;
	while(true) {
		if ($_GET['small_images'.$i]) {
			$images = $_GET['small_images'.$i];
			$imgpath = http_get_file($images, BASE_PATH.'img',"jpg");
			$_item = array();
			$_item['msg'] = $imgpath;
			$_item['msg_type'] = 3;
			cat_send_msg($_wx, $_item);
			sleep(2);
		} else {
			break;
		}
		++$i;
	}
	// 随机一个表情
	$rand_emoji = $emoji_array[array_rand($emoji_array)];
	// 发送短语标题
	$_item = array();
	$_item['msg'] = "{$rand_emoji}{$_GET['item_description']}";
	$_item['msg_type'] = 1;
	cat_send_msg($_wx, $_item);
	sleep(2);

	// 随机一个表情
	$rand_emoji = $emoji_array[array_rand($emoji_array)];
	// 发送短语标题
	$_item = array();
	$_item['msg'] = "{$rand_emoji}{$_GET['title']}";
	$_item['msg_type'] = 1;
	cat_send_msg($_wx, $_item);
	sleep(2);

	// 转换链接
	$share_sheft_url_info = getTaokoulingTbkPrivilege($_GET['item_id'], "110126350144", "1382650485","2207473775157", $_GET['taobao_ance']);
	$share_sheft_url = $share_sheft_url_info['result']['data']['coupon_click_url'];

	// 生成口令
	$Tpwd = createTaobaoTbkTpwd($_GET['taobao_ance'], "美淘优惠券口令", $share_sheft_url)['data']['model'];

	// 随机一个表情
	$rand_emoji = $emoji_array[array_rand($emoji_array)];

	// 券后价
	$co_final_price = sprintf("%.2f", $_GET['zk_final_price']-$_GET['coupon_amount']);

	$conpon_stage = "[@emoji=\uD83D\uDCE2]抢购链接\n".
		"—————————————\n".
		"原价：{$_GET['zk_final_price']} 元\n".
		"优惠券：{$_GET['coupon_amount']} 元\n".
		"券后价：【{$co_final_price}】元{$rand_emoji} \n";

	$tbkTpwd = "[@emoji=\uD83D\uDC49]復製整条{$Tpwd}\n进入【TáǒBáǒ】即可抢购";
	$item = array();
	$item['msg_type'] = 1;	// 1.回复消息 3.回复图片 43.回复视频 2004.回复文件 47.回复表情 49.回复链接
	$item['msg'] = "{$conpon_stage}{$tbkTpwd}";
	cat_send_msg($_wx, $item);
	$conpon_stage = str_replace('\\', '\\\\', $conpon_stage);
	$tbkTpwd = str_replace('\\', '\\\\', $tbkTpwd);
	simQuery("INSERT INTO item_send_catalog (shop_type, shop_name, price, concessional_price, final_price, wx_id, shop_code, clerk, pass_word) VALUES ".
		"(1, '{$_GET['cat_leaf_name']}', {$_GET['zk_final_price']}, {$_GET['coupon_amount']}, {$co_final_price}, {$_GET['wx_id']}, {$_GET['item_id']}, '{$conpon_stage}', '{$tbkTpwd}')");
	echo json_encode(array("result" => "成功"));
	exit();
?>